package com.baidu.service.impl;

import com.baidu.model.entity.PhotoModel;
import com.baidu.model.entity.PhotoModelWithBLOBs;
import com.baidu.model.entity.example.PhotoModelExample;
import com.baidu.model.mapper.PhotoModelMapper;
import com.baidu.service.InPhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author user
 */
@Service
public class PhotoServiceImpl implements InPhotoService {
    @Autowired
    private PhotoModelMapper phoneMapper;

    @Autowired
    private PhotoServiceImpl photoService;

    @Override
    public int phoneUpLoad(PhotoModelWithBLOBs photoModel) throws Exception {
        return phoneMapper.insertSelective(photoModel);
    }

    @Override
    public PhotoModelWithBLOBs selectByFileId(Integer id) {
        return phoneMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<PhotoModel> selectByAlbumId(Integer id, Integer orders, HttpServletRequest request) {
        PhotoModelExample photoModelExample = new PhotoModelExample();
        photoModelExample.createCriteria().andAlbumIdEqualTo(id).andOrdersGreaterThanOrEqualTo(orders);
        return phoneMapper.selectByExample(photoModelExample);
    }

    @Override
    public int deletePhotoById(Integer id) throws Exception{
        return phoneMapper.deleteByPrimaryKey(id);
    }

}
